/*
 * $Id$
 *
 * Copyright 2008 HuangHuang. All rights reserved.
 */
package com.crm.dao.impl;

import com.crm.dao.ISloggerDao;
import com.crm.model.SysLog;

import java.util.List;
import java.util.Date;

import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

/**
 * @author <a href="mailto:huang0510@hotmail.com">HuangHuang</a>
 * @version $Id$
 */
public class SloggerDao extends BaseDao implements ISloggerDao {

    /**
     * {@inheritDoc}
     */
    public void saveOrUpdate(SysLog slog) {
        getHibernateTemplate().saveOrUpdate(slog);
    }

    /**
     * {@inheritDoc}
     */
    public List getLoggers() {
        return getHibernateTemplate().find("from SysLog");
    }

    /**
     * {@inheritDoc}
     */
    public List getLoggersByAction(String action) {
        return getHibernateTemplate().find("from SysLog where action=?", action);
    }

    /**
     * {@inheritDoc}
     */
    public List getLoggersByDate(java.util.Date date) {
        return getHibernateTemplate().find("from SysLog where logDate=?", date);
    }

    /**
     * {@inheritDoc}
     */
    public void delete(SysLog log) {
        getHibernateTemplate().delete(log);
    }

    /**
     * {@inheritDoc}
     */    
    public List getStatistic(final String target, final Date fromDate, final Date toDate) {
        return getHibernateTemplate().executeFind(new HibernateCallback() {
            public Object doInHibernate(Session session) {
                return session.getNamedQuery("statisticQuerySql")
                        .setString("target", target)
                        .setDate("fromDate", fromDate)
                        .setDate("toDate", toDate)
                        .list();
            }
        });

    }
}
